﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using EmoneyWeiXinEntity;
using EmoneyWeiXinThreadDAL;
using EmoneyWeiXinCommon;

namespace EmoneyWeiXinThreadBLL
{
    public class StockDoctorPhoneLogBLL
    {
        public static object objLog = new object();
        public static int threadnum = 1;
        public static List<StockDoctorlogEntity> listdiclog = new List<StockDoctorlogEntity>();
        public static List<StockDoctorlogEntity> listdiclog1 = new List<StockDoctorlogEntity>();
        public static List<StockDoctorlogEntity> listdiclog2 = new List<StockDoctorlogEntity>();
        public static List<string> listStr = new List<string>();

        public static void GetStockDoctorPhoneLog()
        {
            while (true)
            {
                try
                {
                    lock (objLog)
                    {
                        if (threadnum == 1)
                        {
                            threadnum = 2;
                            listdiclog = listdiclog1;
                            listdiclog1 = new List<StockDoctorlogEntity>();
                        }
                        else
                        {
                            threadnum = 1;
                            listdiclog = listdiclog2;
                            listdiclog2 = new List<StockDoctorlogEntity>();
                        }
                    }

                    if (listdiclog != null && listdiclog.Count > 0)
                    {

                        weixinUserDal dalWeixinuser = new weixinUserDal();
                        for (var i = 0; i < listdiclog.Count; i++)
                        {
                            if (listdiclog[i].wType != 2)
                            {
                                dalWeixinuser.getStockDoctorlogUpdate(listdiclog[i]);
                            }
                            else
                            {
                                dalWeixinuser.getStockDoctorlog2Update(listdiclog[i]);
                            }
                        }

                    }
                    Thread.Sleep(1000 * 60);
                    listdiclog = new List<StockDoctorlogEntity>();
                }
                catch (NullReferenceException ex)
                {
                    MyTrace.get().add("StockDoctorPhoneLogBLL.GetStockDoctorPhoneLog--空对象错误：" + ex.Source);
                }
                catch (Exception ex)
                {
                    MyTrace.get().add("StockDoctorPhoneLogBLL.GetStockDoctorPhoneLog--发生异常：" + ex.Message);
                }

            }
        }

        public static void SetStockDoctorPhoneLog(StockDoctorlogEntity logentity)
        {
            objLog = "";
            if (threadnum == 1)
            {

                listdiclog1.Add(logentity);
            }
            else
            {
                listdiclog2.Add(logentity);
            }
        }

       
        
    }
}
